import loadingUrl from '@/assets/loading.svg';
import style from '../style/loading.module.less'

function getLoading(el){
    return el.querySelector('img[data-id=loading]');
}

function createLoading(){
    const img = document.createElement('img');
    img.dataset.id = 'loading';
    img.className = style.loading;
    img.src = loadingUrl;
    return img;
}

export default function(el, binding){
    const curImg = getLoading(el);
    if(binding.value){
        if(!curImg){
            const img = createLoading();
            el.appendChild(img);
        }
    }else{
        if(curImg){
            curImg.remove();
        }
    }
}